#include <stdio.h>
#include <stdlib.h>
struct bus
{
	int route;
	char start[10];
	char end[10];
	int mileage;
};

int main(void)
{
	struct bus circuit[] = {
				{1,"北站","南站",555},
				{2,"东站","西站",666},
				{3,"左站","右站",777},
				{4,"上站","下站",888}
				};
	int n = sizeof circuit / sizeof circuit[0];
	FILE* fp;
	if(!(fp = fopen("bus.dat","w+")))
	{
		puts("文件打开失败!");
		return -1;
	}
	fwrite(circuit, sizeof(struct bus), n, fp);
	fseek(fp, 0, 0);
	struct bus bus[n];
	fread(bus, sizeof(struct bus), n, fp);
	register int i = 0;
	for(; i < n; i++)
	{
		printf("线路:%d,起始站:%s,终点站:%s,里程:%d\n",bus[i].route,bus[i].start,bus[i].end,bus[i].mileage);
	}
	fclose(fp);
}
